import Mock from "mockjs";
const Random = Mock.Random;

Mock.mock("/api/user", "get", {
  code: 200,
  message: "操作成功",
  data: {
    id: 1,
    name: '@cname', // 随机生成中文名字
    gender: Random.pick(["男", "女"]), // 随机生成性别
  },
})

const users = Mock.mock({
    'list|1-10': [{
        'id|+1': 1,
        name: '@cname',
        gender: Random.pick(["男", "女"]),
    }]
})

Mock.mock("/api/person/list", "get", {
    code: 200,
    message: "操作成功",
    data: users.list
})

Mock.mock("/\/api\/person\/getUserById", "get",(req,res) =>{

    const id= req.url.match(/id=(\d+)/)[1];
    const user = users.list.find(user => user.id == id)
    return {
        code: 200,
        message: "操作成功",
        data: user
    }
})